package com.nx.controller;

import com.nx.entity.User;
import com.nx.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController {

	@Autowired
    private IUserService userService;

	//添加用户
	@RequestMapping("save")
	public String save() {
		User user = new User();
		user.setUserid("1.0");
		user.setName("ss");
		user.setAge(2000);
		//userService.save(user);
		userService.insert(user);
		return "SSUCCESS";
	}

	//根据userid删除用户
	@RequestMapping("deleteByuserid")
	public String deleteByuserid(String userid) {
		userService.remove(userid);
		return "SSUCCESS";
	}

	//根据id更新文档
	@RequestMapping("updateByuserid")
	public String updateByusserid() {
		User user = new User();
		user.setUserid("1.0");
		user.setName("sss");
		user.setAge(20);
		userService.update(user);
		return "SSUCCESS";
	}

	//单条件查询，find查询所有
	@RequestMapping("findByuserid")
	public List<User> findByuserid(String userid) {
		return userService.findByUid(userid);
	}

	//多条件查询，find查询所有
	@RequestMapping("findByuseridandname")
	public List<User> findByuseridandname(String userid, String name) {
		return userService.findByUidAndTimestamp(userid, name);
	}

	//根据uid分页查询
	@RequestMapping("page")
	public List<User> page(int page,String userid){
		return userService.page(page, userid);
	}
}